﻿<UserControl x:Class="WcfClientGenerator.UI.View.ConfigurationsView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:vwm="clr-namespace:WcfClientGenerator.UI.ViewModel"
             xmlns:model="clr-namespace:WcfClientGenerator.Model.Config;assembly=WcfClientGenerator.Model.v2"
             xmlns:conv="clr-namespace:WcfClientGenerator.UI.Converters"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <conv:ObjectVisibilityConverter x:Key="objectVisibilityConverter" />
        <conv:BoolVisibilityConverter x:Key="boolVisibilityConverter" />
        <conv:ConfigurationImageConverter x:Key="configurationImageConverter" />
        <conv:ConfigurationBackgroundConverter x:Key="configurationBackgroundConverter" />
        <DataTemplate x:Key="tptConfigurationItemTemplate" DataType="{x:Type model:WcfClientConfiguration}">
            <Grid Margin="5"
                Width="73" Height="73"
                Background="{Binding Path=TileBackgroundIndex, Converter={StaticResource configurationBackgroundConverter}}"
                ToolTip="{Binding Path=Name}">
                <Grid.RowDefinitions>
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Image Source="{Binding Path=TileImage, Converter={StaticResource configurationImageConverter}}"
                    Width="48" Height="48"
                    Margin="4"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Center"
                    Grid.Row="0"/>
                <TextBlock
                    Text="{Binding Path=Name}"
                    VerticalAlignment="Center"
                    HorizontalAlignment="Left"
                    Margin="2,0,2,2"
                    TextTrimming="CharacterEllipsis" 
                    Grid.Row="1"/>
            </Grid>
        </DataTemplate>
    </UserControl.Resources>
    <Grid x:Name="grdRoot"
          Style="{DynamicResource rootLayoutStyle}">
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ListBox x:Name="lstConfigurations" 
                 ItemTemplate="{StaticResource tptConfigurationItemTemplate}" 
                 ItemsSource="{Binding Path=ClientConfigurations}"
                 SelectedItem="{Binding Path=SelectedConfiguration, Mode=TwoWay}"
                 Grid.Row="0" 
                 Margin="0"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                 Style="{DynamicResource projectListStyle}">
            <ListBox.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapPanel 
                        Style="{DynamicResource projectListItemsPanelStyle}"/>
                </ItemsPanelTemplate>
            </ListBox.ItemsPanel>
            <ListBox.ContextMenu>
                <ContextMenu Visibility="{Binding CanCopyPasteConfigurations, Converter={StaticResource boolVisibilityConverter}}">
                    <MenuItem Header="Copy" Command="{Binding CopySelectedConfigurationToClipboardCommand}" />
                    <MenuItem Header="Paste" Command="{Binding AddConfigurationFromClipboardCommand}" />
                    <MenuItem Header="E-mail" Command="{Binding EMailSelectedConfigurationCommand}" />
                </ContextMenu>
            </ListBox.ContextMenu>
        </ListBox>
        <TextBlock x:Name="txtMessage"
                   Grid.Row="1"
                   Style="{DynamicResource validationMessageStyle}"
                   Text="{Binding Path=ValidationMessage}"
                   Visibility="{Binding Path=ValidationMessage, Converter={StaticResource objectVisibilityConverter}}"/>
    </Grid>
</UserControl>
